package com.example.administrator.luckpan;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.method.CharacterPickerDialog;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.ImageButton;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
    private ImageButton btn ;
    private LuckyPan mLuckyPan ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn = (ImageButton) findViewById(R.id.b) ;
        mLuckyPan = (LuckyPan) findViewById(R.id.luckypan) ;
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 if (!mLuckyPan.isStart()){
                     Random r = new Random() ;
                     int i = r.nextInt(6) ;
                     Log.i("Log","zhi:"+i) ;
                     if (i == 2){
                         i = 0 ;
                     }
                     mLuckyPan.luckyStart(i); ;
                     btn.setImageResource(R.drawable.sp);
                 }else {
                     if (!mLuckyPan.isShouldEnd()){
                         mLuckyPan.luckyStop();
                         btn.setImageResource(R.drawable.st);
                     }
                 }
            }
        });

    }

}
